
/****** Object:  StoredProcedure [proc_SuppliersLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SuppliersLoadByPrimaryKey]
(
	@SupplierID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SupplierID],
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	FROM [Suppliers]
	WHERE
		([SupplierID] = @SupplierID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadAll];
GO

CREATE PROCEDURE [proc_SuppliersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SupplierID],
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	FROM [Suppliers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersUpdate];
GO

CREATE PROCEDURE [proc_SuppliersUpdate]
(
	@SupplierID int,
	@SupplierName nvarchar(50) = NULL,
	@SupplierPhone nvarchar(50) = NULL,
	@SupplierTotalBalance float = NULL,
	@SupplierPaidBalance float = NULL,
	@SupplierRemainBalance float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Suppliers]
	SET
		[SupplierName] = @SupplierName,
		[SupplierPhone] = @SupplierPhone,
		[SupplierTotalBalance] = @SupplierTotalBalance,
		[SupplierPaidBalance] = @SupplierPaidBalance,
		[SupplierRemainBalance] = @SupplierRemainBalance
	WHERE
		[SupplierID] = @SupplierID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SuppliersInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersInsert];
GO

CREATE PROCEDURE [proc_SuppliersInsert]
(
	@SupplierID int = NULL output,
	@SupplierName nvarchar(50) = NULL,
	@SupplierPhone nvarchar(50) = NULL,
	@SupplierTotalBalance float = NULL,
	@SupplierPaidBalance float = NULL,
	@SupplierRemainBalance float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Suppliers]
	(
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	)
	VALUES
	(
		@SupplierName,
		@SupplierPhone,
		@SupplierTotalBalance,
		@SupplierPaidBalance,
		@SupplierRemainBalance
	)

	SET @Err = @@Error

	SELECT @SupplierID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersDelete];
GO

CREATE PROCEDURE [proc_SuppliersDelete]
(
	@SupplierID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Suppliers]
	WHERE
		[SupplierID] = @SupplierID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersDelete Error on Creation'
GO
